# Copyright (c) 2009 by Alex Leone <acleone ~at~ gmail.com>
#
# This file is part of epp.
#
# epp is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# epp is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with epp.  If not, see <http://www.gnu.org/licenses/>.

r"""
Contains the [undef] tag.

Syntax:
    [undef tag1 tag2 ...]
    [undefine tag1 tag2 ...]

Outputs:
    Nothing ('')

Examples:
    Note: s[1:] in p.parsetags(s[1:]) is to strip the leading '\n'
          from s

    >>> import epp
    >>> p = epp.Epp()
    >>> s = '''
    ... [define tag1=""]
    ... [ifdef tag1:]
    ...  tag1 is defined!
    ... [undef tag1]
    ... [ifndef tag1:]
    ...  tag1 is no longer defined'''
    >>> print(p.parsetags(s[1:]))
    tag1 is defined!
    tag1 is no longer defined
"""

import tags
from tags.tag import Tag

tagnames = ["undef", "undefine"]

class Undef(Tag):

    def replace(self, eppinst, tagName, attrs):
        """
        Undefines a tag.
        Returns: '' (no replacement text)
        """
        for attrName, value in attrs:
            if attrName in eppinst._tags:
                eppinst._print_message(
                        "[%s]-ed %r"
                        % (tagName, attrName), 4)
                del eppinst._tags[attrName]
        return ''